package lab02.test23;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;

/**
 * Created by dell on 2017/10/31.
 */
public class Test {
    int year = 0;
    int month = 0;
    int day = 0;
    Calendar cld = Calendar.getInstance();//创建一个日历
    public Test(){
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入年：月：日：");
        try {
            year = Integer.parseInt(in.readLine());
            month = Integer.parseInt(in.readLine());
            day = Integer.parseInt(in.readLine());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //将日历时间设置成生日那天
    public void setDate(int year,int month,int day){
        cld.set(year,month-1,day);
    }
    //获取该日是一年当中的第几天
    public int getDay(){
        return cld.get(6);
    }
    //获取该日是星期几
    public String getDate(){
        int date = cld.get(7);
        return getWeekday(date);
    }
    //判断解析一周7天的值
    public String getWeekday(int dayofweek){
        switch(dayofweek){
            case 1: return "星期日";
            case 2: return "星期一";
            case 3: return "星期二";
            case 4: return "星期三";
            case 5: return "星期四";
            case 6: return "星期五";
            case 7: return "星期六";
            default:return "error";
        }
    }
    public static void main(String[] args) {
       Test gb = new Test();
        gb.setDate(gb.year, gb.month, gb.day);
        System.out.println(gb.getDay());
        System.out.println(gb.getDate());
    }
}
